package com.yzh.design.demo.factory.impl;

import com.alibaba.fastjson.JSON;
import com.yzh.design.demo.ICommodity;
import com.yzh.design.demo.goods.DeliverReq;
import com.yzh.design.demo.goods.GoodsService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Map;

public class GoodsCommodityService implements ICommodity {
    private Logger logger = LoggerFactory.getLogger(CouponCommodityService.class);
    private GoodsService service = new GoodsService();

    @Override
    public void sendCommodity(String Uid, String commodityId, String bizId, Map<String, String> extMap) {
        DeliverReq deliverReq = new DeliverReq();
        deliverReq.setUserName(queryUserName(Uid));
        deliverReq.setUserPhone(queryUserPhoneNumber(Uid));
        deliverReq.setSku(commodityId);
        deliverReq.setOrderId(bizId);
        deliverReq.setConsigneeUserName(extMap.get("consigneeUserName"));
        deliverReq.setConsigneeUserPhone(extMap.get("consigneeUserPhone"));
        deliverReq.setConsigneeUserAddress(extMap.get("consigneeUserAddress"));
        Boolean isSuccess = service.deliverGoods(deliverReq);
        logger.info("请求参数[优惠券] => uId：{} commodityId：{} bizId：{} extMap：{}", Uid, commodityId, bizId, JSON.toJSON(extMap));
        logger.info("测试结果[优惠券]：{}", isSuccess);
        if (!isSuccess) throw new RuntimeException("实物商品发放失败");
    }
    private String queryUserName(String uId) {
        return "杨子豪";
    }

    private String queryUserPhoneNumber(String uId) {
        return "15663186666";
    }
}
